<template>
  <j-modal
    title="分发"
    :width="600"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="formRef" :rules="rules" :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-form-model-item label="选择单位">
          <z-linkage-area placeholder="请选择选择单位" v-model="model.detectAreaIdArr"/>
        </a-form-model-item>
      </a-form-model>
    </a-spin>
    <template slot="footer">
      <a-button key="back" @click="handleCancel">取消</a-button>
      <a-button key="submit" type="primary" @click="handleOk">确定</a-button>
    </template>
  </j-modal>
</template>

<script>
import Vue from 'vue'
import { USER_INFO } from '@/store/mutation-types'
import * as caseEventApi from '@/api/wxSmuggle/caseEvent.js'
import * as alarmApi from '@/api/wxSmuggle/alarm.js'
import CustomTable from '@/components/zxd/Table/CustomTable'
export default {
  name: 'disposeModal',
  components: {
    CustomTable
  },
  props: {
    taskId: {
      type: [String, Number]
    }
  },
  data() {
    return {
      title: '',
      visible: false,
      disableSubmit: false,
      result: {},
      type: 1,
      model: {},
      form: {
        operationModule: 2 // 1.告警中心，2.告警一张图, 3.告警中心-详情处置,4. 重点人管理（审计日志用）
      },
      labelCol: { span: 3},
      wrapperCol: { span: 21 },
      rules: {
        disposal: [
          { required: true, message: '请填写处置说明', trigger: 'change' },
          { min: 1, max: 150, message: '处置内容最多填写150字', trigger: 'change' }
        ]
      },
      confirmLoading: false,
      loading: false,
      selectedKeys: null
    }
  },
  computed: {},
  methods: {
    add() {
      this.visible = true
      this.$nextTick(() => {})
    },
    edit(record, operationModule) {
      this.visible = true
      this.form.operationModule = operationModule
      if (Array.isArray(record)) {
        let ids = record && record.length > 0 ? record.map(v => v.ids) : []
        let targetName = record && record.length > 0 ? record.map(v => v.targetName).join('') : ''
        this.$set(this.form, 'ids', ids)
        this.$set(this.model, 'person', targetName)
      } else {
        let ids = record.ids ? record.ids.split(',') : []
        this.$set(this.form, 'ids', ids)
        if (record.targetName) {
          this.$set(this.model, 'person', record.targetName)
        } else {
          let targetName =
            record && record.person && record.person.length > 0 ? record.person.map(v => v.codeName).join(',') : ''
          this.$set(this.model, 'person', targetName)
        }
      }
      this.getDetails()
      this.$nextTick(() => {})
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      // this.$set(this.form, 'status', 1)
      // this.$refs.formRef.validate(valid => {
      //   if (valid) {
      //     alarmApi
      //       .batchStatus(this.form)
      //       .then(res => {
      //         if (res.success) {
      //           let message = res.message ? res.message : '操作成功'
      //           this.$message.success(message)
      //           this.visible = false
      //           this.$emit('ok')
      //         } else {
      //           this.$message.warn(res.message)
      //         }
      //       })
      //       .catch(e => {
      //         this.$message.warn('操作失败！')
      //       })
      //   } else {
      //     console.log('error submit!!')
      //     return false
      //   }
      // })
    },
    getDetails() {
      let userInfo = Vue.ls.get(USER_INFO)
      caseEventApi
        .details({ taskId: this.taskId })
        .then(res => {
          if (res.success) {
            let result = res.result
            this.$set(this.model, 'incidentName', result.incidentName)
            this.$set(this.model, 'taskName', result.taskName)
            this.$set(this.form, 'disposalUserId', userInfo.id)
            this.$set(this.form, 'disposalUserName', userInfo.realname)
          } else {
            this.$message.warn(res.message)
          }
        })
        .catch(e => {
          this.$message.warn('操作失败！')
        })
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>
<style lang="less" scoped></style>
